<script type="text/javascript">
$(document).ready(function(){
	$("#mode").change(function(){
		var mode = $(this).val();
		if(mode=='month'){
			$("#tr_month").show();
			$("#tr_year").hide();
		}
		else if(mode=='year'){
			$("#tr_month").hide();
			$("#tr_year").show();
		}
	})
	
	var count = 0;
	$(".count").each(function(){
		count += parseInt($(this).text());
	});
	$(".rscount").text(count);
})
</script>
<h2>รายงานสรุปจำนวนวัตถุประสงค์ในการนำข้อมูลไปใช้</h2>
<form method="get" action="admin_report/report_5">
	<div id="advancedSearch">
		<table width="95%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td colspan="2"  class="topic_advancedSearch"><img src="images/topic_advancedSearch2.gif" /></td>
		  </tr>		  	 
		  <tr id="tr_month">
			<td width="180"><br>ปี</td>
			<td>
				<select name="start_year">
					<? 
					$cyear= date("Y");
					for($i=0;$i<10;$i++):
						$year=$cyear-$i;
					?>
					<option value="<?=$year;?>" <?=(@$_GET['start_year'] == $year)?"selected=selected":"";?>><?=$year+543;?></option>
					<? endfor;?>					
				</select>							
			</td>
		  </tr>	
		  	<tr id="tr_month">
			<td width="180"><br>เดือน</td>
			<td>
				<select name="month">
					<? 
					$month = get_month();
					foreach($month as $key=>$item):
					?>
					<option value="<?=$key;?>" <?=(@$_GET['month'] == $key)?"selected=selected":"";?>><?=$item;?></option>
					<? endforeach;?>					
				</select>							
			</td>
		  </tr>	
		  <tr>
			<td width="180"><br>ประเภทข้อมูล</td>
			<td>
				<?=form_dropdown('id',get_option('id','name','suggess_detail'),@$_GET['id'],'','--เลือกทั้งหมด--');?>
			</td>
		  </tr>				  
		  <tr>
			<td>&nbsp;</td>
			<td><input type="submit" name="submit" value="ค้นหา" ></td>
		  </tr>
		</table>
	</div>
</form>

<?php if($_GET):?>
<div id="main-content">
	<table class="tbContainer">
		<tr>
			<td>
			
				<table border="0" cellpadding="10" cellspacing="0" width=""  >
						<tr class="ui-state-error">
							<td colspan="3" class="ui-state-error tdlist" style="text-align:center;">ปี <?=$_GET['start_year']+543?></td>
						</tr>
						<tr class="ui-state-error">							
							<td class="ui-state-error tdlist" style="width:150px;">วัตถุประสงค์</td>
							<td class="ui-state-error tdlist" style="text-align: center;width:250px;">จำนวนในการตอบ (ครั้ง)</td>							
						</tr>
						<?php foreach($suggess_details as $detail):?>
							<tr>
							<td class="tdlist"><?=$detail['name']?></td>
							<td class="tdlist count" style="text-align: right;padding-right: 20px;">
								<?php
									$condition = ($_GET['month'] != '00')?" and
									month(suggess_result.created) = ".$_GET['month']:"";
									$sql = "SELECT
									count(suggess_result.id) as suggess_count
									FROM
									suggess_result
									where
									suggess_detail_id = ".$detail['id']." and
									year(suggess_result.created) = ".$_GET['start_year'].$condition;
									
									$s_result = $this->suggess_result->get($sql);
									echo $s_result[0]['suggess_count'];
								?>
							</td>
							</tr>
						<?php endforeach;?>
						<tr class="ui-state-error">
							
							<td class="ui-state-error tdlist" style="width:150px;">รวม</td>
							<td class="ui-state-error tdlist rscount" style="text-align: right;padding-right: 20px;"></td>							
						</tr>
				</table>				
			</td>
		</tr>
	</table>
</div> 
<?php endif;?>  